<template>
    <div class="goods">
        <router-link :to="{name:'goodsinfo',params:{id:item.id}}" class="goods-list" v-for="item in goodslist" :key="item.id">
            <img :src="item.img_url">
            <p class="title">{{item.title}}</p>
            <div>
                <p class="goods-jg"><span>￥{{item.sell_price}}</span><span>￥{{item.market_price}}</span></p>
                <p class="goods-rm"><span>热卖中</span><span>剩{{item.stock_quantity}}件</span></p>
            </div>
        </router-link>
        <mt-button size="large" @click="getcli" type="danger" plain>加载更多</mt-button>
    </div>
</template>
<script>
export default {
    data () {
        return {
            goodslist:[],
            pageindex:1
        }
    },
    created(){
        this.getGoods();
    },
    methods:{
        getGoods(){
            this.$axios.get('api/getgoods?pageindex='+this.pageindex).then(res=>{
                console.log(res.data.message)
                if(res.data.status===0){
                    // 加载更多是拼接数据
                    this.goodslist=this.goodslist.concat(res.data.message)
                    // this.goodslist=res.data.message;
                }
            })
        },
        getcli(){
            this.pageindex++;
            this.getGoods();
        }
    }
}
</script>
<style lang="scss" scoped>
.goods{
    margin-bottom: 45px;
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    padding: 7px;
    .goods-list{
        width: 49%;
        // border: 1px solid #999;
        box-shadow: 0px 0px 5px #C1C1C1;
        padding: 3px;
        margin: 4px 0px; 
       display: flex;
       flex-direction: column;
       justify-content: space-between;
        img{
            width: 100%;
            min-height: 200px;
        }
        .title{
            color: #333;
            font-size: 14px;
        }
        .goods-jg{
            font-size: 12px;
           :nth-child(1){
               color: red;
               padding-right: 10px;
           }
           :nth-child(2){
               text-decoration:line-through
           }
        }
        .goods-rm{
            font-size: 12px;
            display: flex;
            justify-content: space-between;
        }
    }
}
</style>
